$(document).ready(function() {
	var intMaxLength	= 200;
	$("#frmComment").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {				
			pcontent: {
				required	: true,
				minlength	: 5,
				maxlength	: intMaxLength
			},
			pchk: {
				min			: 1
			}
		},
		messages: {	
			pcontent: {
				required	: content_required,
				minlength	: content_minlength,
				maxlength	: content_maxlength
			},
			pchk: {
				min			: rating_required
			}
		},
		errorPlacement: function(label, element) {				
			var id = element.attr('id');
			if(id == "pchk") {
				label.insertAfter($('#star_rating'));	
			} else {
				label.insertAfter($('#' + id));			
			}
		},
		submitHandler: function(form) {								
			var strContent		= encodeURIComponent($('#pcontent').val());
			var intPlaceId 		= $('#pplaceid').val();
			var intRating		= $('#pchk').val();	
			$.getJSON(				
				HOST_VFRIEND + 'comment/placecmtsend?content='+strContent+'&placeid='+intPlaceId+'&rate='+intRating+'&callback=?',		
				function(response) {					
					if(response['error'] == 0) {
						closeUI();						
						showUIMessage(response['msg']);
						$('#btnRating').remove();
						$('#sComment').html(response['data']);
						$('#scrollCmt').jScrollPane().data('jsp').scrollToBottom();		
						$('.srating').html(response['rating']);
					} else {
						alert(response['msg']);
					}
				}
			);
		}
	});	
	$("textarea#pcontent").autoResize({
		// On resize:
		onResize : function() {
			$(this).css({opacity:0.8});
		},
		// After resize:
		animateCallback : function() {
			$(this).css({opacity:1});
		},
		// Quite slow animation:
		animateDuration : 300,
		// More extra space:
		extraSpace : 5
	});
	$("#pcontent").each(function(){  
		var length = intMaxLength - $(this).val().length;		
		$(this).parent().find("#spanCount").html( length);  
		$(this).keyup(function(){  			
			var new_length = intMaxLength - $(this).val().length; 
			$(this).parent().find("#spanCount").html( new_length);  
		});  
		
	});
	$('#scrollCmt').jScrollPane().data('jsp').scrollToBottom();  
});
$('#star_rating').click(function(){
	var intRating = $('input:radio[name=prating]:checked').val();
	$('#pchk').val(intRating);		
});

